from rest_framework.views import APIView
from rest_framework.response import Response
import string
import secrets
import json

class RandomPasswordView(APIView):
    def get(self, request):
        # 设置密码长度
        password_length = int(request.query_params.get('password_length'))
        # 生成随机密码
        password = ''.join(secrets.choice(string.ascii_letters + string.digits) for i in range(password_length))
        # 返回密码作为JSON响应
        res = {'code': 200, 'msg':'生成密码成功','password': password}
        return Response(res)

